package server;

import java.io.Serializable;
/**
 * An log entry inside the database regarding decisions on the diffrent rules.
 */
public class Log implements Serializable {
	private static final long serialVersionUID = 8108957583000878929L;

	public Log() {
	};

	/**
	 * Creates an log entry for an ip rule match.
	 * @param time The timestamp (in seconds since 1970) of the event.
	 * @param direct The direction of the event (incoming/outgoing).
	 * @param sourceIP The source IP of the event.
	 * @param destIp The destination IP of the event.
	 * @param sourcePort The source port of the event.
	 * @param destPort The destination port of the event.
	 * @param protocol The protocol name of the event.
	 * @param action The action of the event (allow / deny).
	 */
	public Log(Long time, directOpt direct, String sourceIP, String destIp, Integer sourcePort, Integer destPort, String protocol, actionOpt action) {
		type = typeOpt.IP;
		this.time = time;
		this.direct = direct;
		this.sourceIp = sourceIP;
		this.destIp = destIp;
		this.sourcePort = sourcePort;
		this.destPort = destPort;
		this.protocol = protocol;
		this.action = action;
	}

	/**
	 * Creates an log entry for an context rule match.
	 * @param time The timestamp (in seconds since 1970) of the event.
	 * @param direct The direction of the event (incoming/outgoing).
	 * @param sourceIP The source IP of the event.
	 * @param destIp The destination IP of the event.
	 * @param sourcePort The source port of the event.
	 * @param destPort The destination port of the event.
	 * @param rulePort The port of the rule definition.
	 * @param ruleProtocol The name of the rule definition.
	 * @param action The action of the event (allow / deny).
	 */
	public Log(Long time, directOpt direct, String sourceIP, String destIp, Integer sourcePort, Integer destPort, Integer rulePort, String ruleProtocol, actionOpt action) {
		type = typeOpt.CONTEXT;
		this.time = time;
		this.direct = direct;
		this.sourceIp = sourceIP;
		this.destIp = destIp;
		this.sourcePort = sourcePort;
		this.destPort = destPort;
		this.action = action;
		this.rulePort = rulePort;
		this.ruleProtocol = ruleProtocol;
	}

	/**
	 * Creates an log filtering entry, NULL entries means ANY.
	 * @param time timestamp..
	 * @param days How manys days log to look back ? NULL = all log.
	 * @param type Which rule to filter ? (IP/CONTEXT/ANY)
	 * @param directOpt Which Direction to filter ? (IN/OUT/ANY)
	 * @param sourceIp Which source IP to filter ?
	 * @param destIp Which destination IP to filter ?
	 * @param sourcePort Which sort port to filter ?
	 * @param destPort Which destination port to filter ?
	 * @param protocol Which protocol name to filter ? 
	 * @param rulePort Which Rule port to filter ?
	 * @param ruleProtocol Which Rule Protocol to filter ?
	 * @param action Which action to filter ? (ACCEPT/DENY/ANY)
	 */

	public static enum typeOpt {IP, CONTEXT};
	public static enum actionOpt {ACCEPT, DENY};
	public static enum directOpt {IN, OUT};
	public Long time = null;
	public typeOpt type = null;
	public directOpt direct = null;
	public String sourceIp = null;
	public String destIp = null;
	public Integer sourcePort = null;
	public Integer destPort = null;
	public String protocol = null;
	public Integer rulePort = null;
	public String ruleProtocol = null;
	public actionOpt action = null;
}

